package com.zhanglijie.base.other.threadlocalDemo;

import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

import com.zhanglijie.base.threadPool.myThreadPool.T;

/**
 * @author zhanglijie
 * @version 1.0
 * @since 1.1.0 2022/7/4 0004 22:12
 */
public class ThreadPoolUseThreadLocalDemo {
    static class ContentDemo{
        Long[] obj = new Long[1024*1024*2];
    }
    static ThreadLocal<ContentDemo> threadLocal = new ThreadLocal<>();
    static final ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(5,5,1,TimeUnit.MINUTES,new LinkedBlockingQueue<>());

    public static void main(String[] args) {
        for (int i = 0; i < 5000; i++) {
            int finalI = i;
            threadPoolExecutor.submit(()->{
              threadLocal.set(new ContentDemo());
                ContentDemo contentDemo = threadLocal.get();

               // ContentDemo contentDemo = new ContentDemo();
                System.out.println(contentDemo);
            });
        }
    }

}
